package com.fuyao.cloud.admin.flow.utils;

import com.dragon.flow.model.flowable.FlowableActHiActinst;
import org.flowable.bpmn.model.SequenceFlow;
import org.flowable.editor.language.json.converter.FyUserTaskJsonConverter;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;

import java.util.Date;
import java.util.UUID;

public class FlowableTaskUtil {

    /**
     * 装组flowable发送节点记录。
     * @param sequenceFlow 流程流向
     * @param taskEntity 任各实体
     * @return
     */
    public static FlowableActHiActinst getFlowableActHiActinst(SequenceFlow sequenceFlow, TaskEntity taskEntity){
        FlowableActHiActinst actHiActinst = new FlowableActHiActinst();
        actHiActinst.setId(UUID.randomUUID().toString());
        actHiActinst.setActId(sequenceFlow.getId());
        actHiActinst.setActName(sequenceFlow.getName());
        actHiActinst.setActType(FyUserTaskJsonConverter.SEQUENCE_FLOW);
        actHiActinst.setRev(1);
        actHiActinst.setProcInstId(taskEntity.getProcessInstanceId());
        actHiActinst.setTaskId(taskEntity.getId());
        actHiActinst.setProcDefId(taskEntity.getProcessDefinitionId());
        actHiActinst.setExecutionId(taskEntity.getExecutionId());
        actHiActinst.setStartTime(new Date());
        actHiActinst.setEndTime(new Date());
        actHiActinst.setTransactionOrder(1);
        actHiActinst.setDuration("0");
        actHiActinst.setTenantId(taskEntity.getTenantId());
        return actHiActinst;
    }
}
